<header class="header navbar bg-white shadow">
  <div class="btn-group tool-button">
    <a class="btn btn-primary navbar-btn" href="/private/cms/channel" data-pjax id="goback"><i class="ti-angle-left"></i> 返回</a>
  </div>
</header>

<div class="content-wrap">
  <div class="wrapper" style="min-height:500px;">
    <section class="panel panel-form">
      <form id="addForm" role="form" class="form-horizontal parsley-form" data-parsley-validate
            action="/private/cms/channel/editDo" method="post">
        <input type="hidden" id="id" name="id" value="<%=obj.id%>">

        <div class="row mb10">
          <div class="col-lg-12">
            <div class="form-group has-feedback">
              <label for="parentId" class="col-sm-2 control-label">上级栏目</label>

              <div class="col-sm-8">
                <div class="input-group">
                  <input id="parentId" type="text" class="form-control" placeholder="不选择默认为顶级栏目" disabled
                         value="<%=typeof parentUnit!='undefined'?parentUnit.name:'' %>"/>

			                             		<span class="input-group-btn">
			                             			<button type="button" class="btn btn-primary" data-toggle="modal"
                                                data-target="#dialogSelectParentUnit"><i class="ti-plus"></i>选择
                                        </button>
			                             		</span>
                </div>
                <input type="hidden" name="parentId" value="<%=typeof parentUnit!='undefined'?parentUnit.id:0 %>">
              </div>
            </div>
            <div class="form-group">
              <label for="name" class="col-sm-2 control-label">栏目名称</label>

              <div class="col-sm-8">
                <input type="text" id="name" class="form-control" name="name" data-parsley-required="true"
                       placeholder="栏目名称" value="<%=obj.name%>">
              </div>
            </div>
            <div class="form-group">
              <label for="url" class="col-sm-2 control-label">URL路径</label>

              <div class="col-sm-8">
                <input type="text" id="url" name="url" value="<%-obj.url||''%>" class="form-control" placeholder="默认为文章类目名称的拼音缩写">

              </div>
            </div>
            <!--<div class="form-group">-->
              <!--<label for="seo_title" class="col-sm-2 control-label">SEO title</label>-->

              <!--<div class="col-sm-8">-->
                <!--<input type="text" id="seo_title" name="seo_title" value="<%-obj.seo_title||''%>" class="form-control" placeholder="默认为文章类目名称">-->

              <!--</div>-->
            <!--</div>-->
            <!--<div class="form-group">-->
              <!--<label for="seo_keywords" class="col-sm-2 control-label">SEO keywords</label>-->

              <!--<div class="col-sm-8">-->
                <!--<input type="text" id="seo_keywords" name="seo_keywords" value="<%-obj.seo_keywords||''%>" class="form-control" placeholder="默认为文章类目名称">-->

                <!--<p class="help-block no-m"></p>-->
              <!--</div>-->
            <!--</div>-->
            <!--<div class="form-group">-->
              <!--<label for="seo_description" class="col-sm-2 control-label">SEO description</label>-->

              <!--<div class="col-sm-8">-->
                <!--<input type="text" id="seo_description" name="seo_description" value="<%-obj.seo_description||''%>" class="form-control" placeholder="默认为文章类目名称">-->

              <!--</div>-->
            <!--</div>-->
            <div class="form-group">
              <label for="homepage" class="col-sm-2 control-label">是否单页</label>
              <div class="col-sm-10">
                <div class="mb5 mt5">
                  <input tabindex="7" type="radio" id="homepage-1" name="homepage" <%if(!obj.homepage){%>checked<%}%> value="false">
                  <label for="homepage-1">否</label>
                </div>
                <div class="mb5">
                  <input tabindex="8" type="radio" id="homepage-2" name="homepage" <%if(obj.homepage){%>checked<%}%> value="true">
                  <label for="homepage-2">是</label>
                </div>
              </div>
              <div class="form-group" style="display: <%if(!obj.homepage){%>none<%}%>" id="div">
                <label for="content" class="col-sm-2 control-label">单页内容</label>

                <div class="col-sm-8">
                  <textarea id="content" name="content" style="width:100%;height:200px;"><%=obj.content||''%></textarea>
                </div>
              </div>
            </div>
          </div>
          <div class="col-lg-3"></div>
          <div class="col-lg-6">
            <div class="form-group text-center">
              <label></label>

              <div>
                <button id="save" TYPE="button" class="btn btn-primary btn-block btn-lg btn-parsley" data-loading-text="正在提交...">提 交</button>
              </div>
            </div>
          </div>
      </form>
    </section>

  </div>
</div>
<a class="exit-offscreen"></a>
<!-- 选择上级单位 -->
<div id="dialogSelectParentUnit" class="modal fade bs-modal-sm" tabindex="-1" role="dialog" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h4 class="modal-title">选择上级菜单</h4>
      </div>
      <div class="modal-body">
        <div class="row">
          <div class="col-xs-12">
            <div id="jsTreeParentUnit" class="demo"></div>
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <div class="pull-left">
          <button type="button" class="btn btn-success" data-dismiss="modal" onclick="selectFirstMenu()">设为顶级菜单</button>
        </div>
        <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
        <button type="button" class="btn btn-primary" onclick="selectParentMenu()">确认选择</button>
      </div>
    </div>
  </div>
</div>
<script language="JavaScript">

  function initTreeView() {
    $("#jsTreeParentUnit").jstree({
      plugins: ["wholerow", "json_data"],
      core: {
        data: {
          dataType: "json",
          url: function (node) {
            return node.id === "#" ? "/private/cms/channel/tree" : "/private/cms/channel/tree?pid=" + node.id
          }
        },
        multiple: false
      }
    }).on("dblclick.jstree", function (node) {
      selectParentMenu();
    });
  }
  //选择父菜单
  function selectParentMenu() {
    var tree = $.jstree.reference("#jsTreeParentUnit");
    var node = tree.get_selected(true);
    $("#addForm #parentId").val(node[0].text);
    $("#addForm input[name='parentId']").val(node[0].id);
    $("#dialogSelectParentUnit").modal("hide");
  }
  function selectFirstMenu() {
    $("#addForm #parentId").val("顶级菜单");
    $("#addForm input[name='parentId']").val("");
    $("#dialogSelectParentUnit").modal("hide");
  }
  $(document).ready(function () {
    initTreeView();
    myForm.init();
    var ue = new baidu.editor.ui.Editor();
    ue.render('content');
    //图标样式 实时预览
    $("input[name=homepage]").on("change", function(){
      if('true'==$(this).val()){
        $("#div").show();
      }else{
        $("#div").hide();
        ue.setContent('');
      }
    });
    $("#save").on("click",function(){
      $("#content").val(ue.getContent());
      $('#addForm').submit();
    });
    $('#addForm').ajaxForm({
      dataType: 'json',
      beforeSubmit: function (arr, form, options) {
        form.find("button:submit").button("loading");
      },
      success: function (data, statusText, xhr, form) {
        if (data.code==0) {
          Toast.success(data.msg);
          setTimeout(function () {
            $("#goback").trigger("click");
          }, 1000);
        } else {
          Toast.error(data.msg);
        }
        form.find("button:submit").button("reset");
      }
    });
  });
</script>
